def groupAnagrams(lists):
    Anagrams_dict = dict()
    for elem in lists:
        current_new = "".join(set(elem))
        if current_new in Anagrams_dict:
            Anagrams_dict[current_new].append(elem)
        else:
            Anagrams_dict[current_new] = [elem]
    return list(Anagrams_dict.values())


def main():
    lists = ["eat", "tea", "tan", "ate", "nat", "bat"]
    print(groupAnagrams(lists))


if __name__ == "__main__":
    main()
